package com.lishao.soccer.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lishao.soccer.bean.entity.TmGameData;
import com.lishao.soccer.bean.entity.TmMember;
import com.lishao.soccer.bean.entity.TmScoreList;
import com.lishao.soccer.dao.TmGameDataMapper;
import com.lishao.soccer.dao.TmScoreListMapper;
import com.lishao.soccer.service.TmGameDataService;
import com.lishao.system.security.providers.SecurityUser;

public class TmGameDataServiceImpl implements TmGameDataService {
	TmGameDataMapper tmGameDataMapper;
	TmScoreListMapper tmScoreListMapper;
	
	public List<TmGameData> selectDataByGame(Long teamId,Long tmGameId){
		Map paraMap = new HashMap();
		paraMap.put("teamId", teamId);paraMap.put("tmGameId", tmGameId);
		return tmGameDataMapper.selectDataByGame(paraMap);
	}
	
	public int deleteById(Long rowId){
		int iResult = tmGameDataMapper.deleteById(rowId);
		return iResult;
	}
	
	public void saveGameData(Long teamId,Long tmGameId,SecurityUser secUser,List<TmGameData> gameDataList){
		for(int i=0;i<gameDataList.size();i++){
			TmGameData tmGameData = gameDataList.get(i);
			if("1".equals(tmGameData.getDeletedFlag())&&tmGameData.getRowId()!=null&&tmGameData.getRowId()!=-1){
				deleteById(tmGameData.getRowId());
			}else{
				tmGameData.setTeamId(teamId);
				tmGameData.setTmGameId(tmGameId);
				tmGameData.setRecordDate(new java.util.Date());
				tmGameData.setRecordUserId(secUser.getSmUser().getRowId());
				if(tmGameData.getRowId()!=null&&tmGameData.getRowId()>0){
					tmGameDataMapper.updateByPrimaryKeySelective(tmGameData);
				}else{
					tmGameDataMapper.insertSelective(tmGameData);
				}
			}
		}
	}
	
	public List<TmGameData> selectGameDataList(Long teamId,Long tmGameId,Date startDate,Date endDate,Long playUserId,Long itemId,String itemType){
    	Map paraMap = new HashMap();
		paraMap.put("teamId", teamId);paraMap.put("tmGameId", tmGameId);
		paraMap.put("startDate", startDate);paraMap.put("endDate", endDate);
		paraMap.put("playUserId", playUserId);
		paraMap.put("itemId", itemId);paraMap.put("itemType", itemType);
		List<TmGameData> gameDataList = tmGameDataMapper.selectDataByUser(paraMap);
		return gameDataList;
    }
    public List<TmGameData> selectGameDataList(Long tmScoreListId,Long playUserId,Long itemId,String itemType){
		TmScoreList tmScoreList = tmScoreListMapper.selectByPrimaryKey(tmScoreListId);
		return selectGameDataList(tmScoreList.getTeamId(), null, tmScoreList.getStartDate(), tmScoreList.getEndDate(),playUserId,itemId,itemType);
	}
	//get set
	public TmGameDataMapper getTmGameDataMapper() {
		return tmGameDataMapper;
	}

	public void setTmGameDataMapper(TmGameDataMapper tmGameDataMapper) {
		this.tmGameDataMapper = tmGameDataMapper;
	}

	public TmScoreListMapper getTmScoreListMapper() {
		return tmScoreListMapper;
	}

	public void setTmScoreListMapper(TmScoreListMapper tmScoreListMapper) {
		this.tmScoreListMapper = tmScoreListMapper;
	}
}
